<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of product
 *
 * @author HIEN JENNY
 */
class Default_Model_Product extends Libs_Model {

    private $pro_id;
    private $pro_name;
    private $pro_price_old;
    private $pro_price;
    private $pro_img;
    private $pro_date;
    private $cate_id;
    private $cates_id;
    private $detail_pro;
    private $substance;
    private $weight;
    private $color_id;
    private $size_id;
    private $style_detail;
    private $number;

    /*
     * mix pro_id
     */

    public function setProId($pro_id) {
        $this->pro_id = $pro_id;
    }

    /*
     * return pro_id
     */

    public function getProId() {
        return $this->pro_id;
    }

    /*
     * mix pro_name
     */

    public function setProName($pro_name) {
        $this->pro_name = $pro_name;
    }

    /*
     * return pro_name
     */

    public function getProName() {
        return $this->pro_name;
    }

    /*
     * mix pro_price_old
     */

    public function setProPriceOld($pro_price_old) {
        $this->pro_price_old = $pro_price_old;
    }

    /*
     * return pro_price_old
     */

    public function getProPriceOld() {
        return $this->pro_price_old;
    }

    /*
     * mix pro_price
     */

    public function setProPrice($pro_price) {
        $this->pro_price = $pro_price;
    }

    /*
     * return pro_price
     */

    public function getProPrice() {
        return $this->pro_price;
    }

    /*
     * mix pro_img
     */

    public function setProImg($pro_img) {
        $this->pro_img = $pro_img;
    }

    /*
     * return pro_img
     */

    public function getProImg() {
        return $this->pro_img;
    }

    /*
     * mix pro_date
     */

    public function setProDate($pro_date) {
        $this->pro_date = $pro_date;
    }

    /*
     * return pro_date
     */

    public function getProDate() {
        return $this->pro_date;
    }

    /*
     * mix cate_id
     */

    public function setCateId($cate_id) {
        $this->cate_id = $cate_id;
    }

    /*
     * return cate_id
     */

    public function getCateId() {
        return $this->cate_id;
    }

    /*
     * mix cates_id
     */

    public function setCatesId($cates_id) {
        $this->cates_id = $cates_id;
    }

    /*
     * return cates_id
     */

    public function getCateSId() {
        return $this->cates_id;
    }

    /*
     * mix detail_pro
     */

    public function setDetailPro($detail_pro) {
        $this->detail_pro = $detail_pro;
    }

    /*
     * return detail_pro
     */

    public function getDetailPro() {
        return $this->detail_pro;
    }

    /*
     * mix substance
     */

    public function setSubstance($substance) {
        $this->substance = $substance;
    }

    /*
     * return substance
     */

    public function getSubstance() {
        return $this->substance;
    }

    /*
     * mix weight
     */

    public function setWeight($weight) {
        $this->weight = $weight;
    }

    /*
     * return weight
     */

    public function getWeight() {
        return $this->weight;
    }

    /*
     * mix color_id
     */

    public function setColorId($color_id) {
        $this->color_id = $color_id;
    }

    /*
     * return color_id
     */

    public function getColorId() {
        return $this->color_id;
    }

    /*
     * mix size_id
     */

    public function setSizeId($size_id) {
        $this->size_id = $size_id;
    }

    /*
     * return size_id
     */

    public function getSizeId() {
        return $this->size_id;
    }

    /*
     * mix style_detail
     */

    public function setStyleDetail($style_detail) {
        $this->style_detail = $style_detail;
    }

    /*
     * return style_detail
     */

    public function getStyleDetail() {
        return $this->style_detail;
    }

    /*
     * mix number
     */

    public function setNumber($number) {
        $this->number = $number;
    }

    /*
     * return number
     */

    public function getNumber() {
        return $this->number;
    }

    protected function setValue($row, $isKey = TRUE) {
        $pro = new Default_Model_Product();
        if ($isKey) {
            $pro->setProId($row['id']);
        }
        $pro->setProName($row['pro_name']);
        $pro->setProPriceOld($row['pro_price_old']);
        $pro->setProPrice($row['pro_price']);
        $pro->setProImg($row['pro_img']);
        $pro->setNumber($row['pro_number']);
        $pro->setProDate($row['pro_date']);
        $pro->setCateId($row['cate_id']);
        $pro->setCatesId($row['cates_id']);
        $pro->setDetailPro($row['detail_pro']);
        $pro->setSubstance($row['substance']);
        $pro->setWeight($row['weight']);
        $pro->setColorId($row['color_id']);
        $pro->setSizeId($row['size_id']);
        $pro->setStyleDetail($row['style_detail']);
        return $pro;
    }

    protected function getKeyAndValue(Default_Model_Product $pro, $isKey = FALSE) {
        $data = array();
        if ($isKey) {
            $data['pro_id'] = $pro->getProId();
        }
        $data['pro_name'] = $pro->getProName();
        $data['pro_price_old'] = $pro->getProPriceOld();
        $data['pro_price']= $pro->getProPrice();
        $data['pro_img'] = $pro->getProImg();
        $data['pro_number']= $pro->getNumber();
        $data['pro_date'] = $pro->getProDate();
        $data['cate_id'] = $pro->getCateId();
        $data['cates_id'] = $pro->getCateSId();
        $data['detail_pro'] = $pro->getDetailPro();
        $data['substance'] = $pro->getSubstance();
        $data['weight'] = $pro->getWeight();
        $data['color_id']=$pro->getColorId();
        $data['size_id']=$pro->getSizeId();
        $data['style_detail'] = $pro->getStyleDetail();
        return $data;
    }

    public function getProduct($id = '') {
        $sql = "SELECT * FROM product ORDER BY pro_date DESC LIMIT 0,9";
        return $this->db->fetchAll($sql);
    }

    public function getProductBetSeller() {
        $sql = "SELECT product.*, count(order_qty) as soluong FROM tbl_detailorder JOIN product ON tbl_detailorder.pro_id = product.id GROUP BY (pro_id) ORDER BY soluong DESC LIMIT 0,9";
        return $this->db->fetchAll($sql);
    }

}

?>
